/*
 * @Descripttion: 
 * @version: 
 * @Author: TT
 * @Date: 2022-06-21 15:28:19
 * @LastEditors: TT
 * @LastEditTime: 2022-06-22 22:20:52
 */

import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:hzy_normal_widget/hzy_normal_widget.dart';
import 'package:hzy_template/config/dataconfig/data_config_index.dart';
import '../../../components/common_index.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../controllers/my_theme_c.dart';

class MyThemeV extends CommonGetXWidget<MyThemeC> {
  MyThemeV({Key? key}) : super(key: key);
  @override
  MyThemeC get controller => Get.put(MyThemeC());
  @override
  String? get title => "深色模式";
  @override
  Color? get backgroundColor => HzyColorConfig().backgroudgrey;
  @override
  Color? get navbackcolor => HzyColorConfig().backgroudgrey;
  @override
  Widget createBody(BuildContext context) {
    return ListView.separated(
      itemBuilder: createItemBuilder,
      separatorBuilder: createSparatorBuilder,
      itemCount: controller.switchValue.value ? 1 : 4,
    );
  }

  Widget createItemBuilder(BuildContext context, int index) {
    Widget body = Container();
    if (index == 0) {
      body = createfirstwidget();
    } else if (index == 1) {
      body = Container(
        padding: EdgeInsets.only(
          left: 20.w,
          right: 20.w,
          top: 10.w,
          bottom: 10.w,
        ),
        child: Text(
          "手动选择",
          style: FontConfig().fontMedium145a5a5a,
        ),
      );
    } else if (index == 2) {
      body = createdarkitemwidget(
        "普通模式",
        index,
      );
    } else if (index == 3) {
      body = createdarkitemwidget(
        "深色模式",
        index,
      );
    }
    return body;
  }

  Widget createSparatorBuilder(BuildContext context, int index) {
    if (index == 2) {
      return Container(
        decoration: BoxDecoration(
            color: HzyThemeColor().confgColor(HzyColorSring.colffffff)),
        child: Container(
          height: 1,
          margin: EdgeInsets.only(left: 20.w, right: 20.w),
          decoration: BoxDecoration(
            color: HzyColorConfig().linecolor,
          ),
        ),
      );
    } else {
      return Container();
    }
  }

  // 创建跟随系统
  Widget createfirstwidget() {
    return Container(
      decoration: BoxDecoration(
        color: HzyColorConfig().whitebackgroundColor,
      ),
      padding: EdgeInsets.only(
        left: 20.w,
        right: 20.w,
        top: 15.w,
        bottom: 15.w,
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          SizedBox(
            width: SizeMacro.screenWidth - 40 - 70,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  "跟随系统",
                  style: FontConfig().fontMedium16Black,
                ),
                Gaps.vGap5,
                Text(
                  "开启后,将跟随系统打开或关闭深色模式",
                  style: FontConfig().fontMedium14PlaceColor,
                ),
              ],
            ),
          ),
          CupertinoSwitch(
            value: controller.switchValue.value,
            dragStartBehavior: DragStartBehavior.down,
            onChanged: (value) {
              controller.configSwitchOnchanged(value);
            },
          )
        ],
      ),
    );
  }

  Widget createdarkitemwidget(String text, int index) {
    return InkWell(
      onTap: () {
        controller.tapdarkitem(index: index);
      },
      child: Container(
        padding: EdgeInsets.only(
          left: 20.w,
          right: 20.w,
          bottom: 10.w,
          top: 10.w,
        ),
        decoration: BoxDecoration(
          color: HzyColorConfig().whitebackgroundColor,
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(text, style: FontConfig().fontMedium14Black),
            Obx(
              () => controller.selectIndex.value == index
                  ? Icon(
                      Icons.check,
                      size: 16.w,
                      color: HzyColorConfig().colthemes,
                    )
                  : Container(),
            )
          ],
        ),
      ),
    );
  }
}
